<template>
  <div class="GRiskReportList">
    <filterPanel filterName="GRiskReportListFilter" filterTitle="分析评估报告查询" :filterList="filterData"
                 @filterChange="filterChange"></filterPanel>
    <tablePanel tableName="GRiskReportListTable" :tableLoading="loading" tableTitle="分析评估报告列表" :tableList="tableList"
                :tableData="tableData" :total="total" :currentPage="form.page_start" :pageSize="form.page_size"
                @sizeChange="sizeChange" @pageChange="pageChange" @tableClick="tableClick">
      <zy-button @click="createReport">生成评估报告</zy-button>
      <dropdownBox title="评估报告设置" :dropList="dropList" @dropdown="dropdown"></dropdownBox>
      <zy-button @click="exportExcel">导出列表</zy-button>
    </tablePanel>
    <reportModel :show="show" :modelType="modelType" @close="close"></reportModel>
    <zyModel title="生成评估报告" :show="showModel" @close="closeModel" @submit="submitModel">
      <div class="createReport">
        <div class="form">
          <div class="form-item">
            <div class="form-item-name required">评估报告类型</div>
            <div class="form-item-cont">
              <el-select v-model="type" modalable placeholder="请选择">
                <el-option v-for="option in typeList" :key="option.value" :label="option.label"
                           :value="option.value"></el-option>
              </el-select>
            </div>
          </div>
          <div class="form-item">
            <div class="form-item-name required">评估对象</div>
            <div class="form-item-cont">
              <el-select v-model="customer_name" modalable placeholder="请选择" filterable>
                <el-option v-for="option in optionList" :key="option.value" :label="option.label"
                           :value="option.value"></el-option>
              </el-select>
            </div>
          </div>
          <div class="form-item">
            <div class="form-item-name required">统计时间</div>
            <div class="form-item-cont">
              <datePicker v-model="time"></datePicker>
            </div>
          </div>
          <div class="form-item">
            <div class="form-item-name">可疑件数量</div>
            <div class="form-item-cont">{{debious_num||'0'}}</div>
          </div>
          <div class="form-item">
            <div class="form-item-name required">评估结果</div>
            <div class="form-item-cont">
              <zy-input placeholder="" v-model="result"></zy-input>
            </div>
          </div>
        </div>
      </div>
    </zyModel>
  </div>
</template>

<script>
	import reportModel from "./reportModel";
	import datePicker from "../../../../components/datePicker/index"

	export default {
		name: "GRiskReportList",
		props: {},
		data() {
			return {
				type: '',
				typeList: [
					{label: '物流企业分析评估', value: '1'},
					{label: '合作站点分析评估', value: '2'},
					{label: '从业人员分析评估', value: '3'},
					{label: '监管辖区分析评估', value: '4'},
					{label: '民警处理数据统计', value: '5'},
				],
				customer_name: '',
				analysis_customer_id: '',
				analysis_customer_name: '',
				optionList: [],
				time: [],
				debious_num: '',
				result: '',
				dropList: [
					{
						name: '物流企业分析评估',
						type: '1',
						disabled: false
					},
					{
						name: '合作站点分析评估',
						type: '2',
						disabled: false
					},
					{
						name: '从业人员分析评估',
						type: '3',
						disabled: false
					}, {
						name: '监管辖区分析评估',
						type: '4',
						disabled: false
					}, {
						name: '民警处理数据统计',
						type: '5',
						disabled: false
					}
				],
				filterData: [
					{
						title: '评估对象',
						name: 'analysis_customer_name',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '评估报告类型',
						name: 'type',
						type: 'select',
						optionList: [
							{label: '全部', value: ''},
							{label: '物流企业分析评估', value: '1'},
							{label: '合作站点分析评估', value: '2'},
							{label: '从业人员分析评估', value: '3'},
							{label: '监管辖区分析评估', value: '4'},
							{label: '民警处理数据统计', value: '5'},
						],
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '生成方式',
						name: 'analysis_type1',
						type: 'select',
						optionList: [
							{label: '全部', value: ''},
							{label: '系统生成', value: '1'},
							{label: '手工生成', value: '2'},
						],
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '统计人',
						name: 'create_name',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '统计时间',
						name: 'time',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
					{
						title: '生成时间',
						name: 'ctime',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
				],
				form: {
					analysis_customer_name: '',
					type: '',
					analysis_type1: '',
					create_name: '',
					time: [],
					ctime: [],
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableList: [
					{
						title: '评估对象',
						width: 120,
						name: 'analysis_customer_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '评估报告类型',
						width: 160,
						name: 'type_str',
						isShow: true,
						isSelected: true
					},
					{
						title: '生成方式',
						width: 120,
						name: 'analysis_type_str',
						isShow: true,
						isSelected: true
					},
					{
						title: '评估结果',
						width: 120,
						name: 'result',
						isShow: true,
						isSelected: true
					},
					{
						title: '统计时间',
						width: 200,
						name: 'out_times',
						isShow: true,
						isSelected: true
					},
					{
						title: '生成时间',
						width: 200,
						name: 'create_time_str',
						isShow: true,
						isSelected: true
					},
					{
						title: '操作',
						width: 200,
						name: 'handler',
						fixed: 'right',
						btns: [
							{
								type: 'detail',
								name: '详情'
							},
							{
								type: 'download',
								name: '下载'
							},
							{
								type: 'put',
								name: '推送消息'
							},
							{
								type: 'delete',
								name: '删除',
								btnType: 'danger'
							},
						],
						isSelected: true
					}
				],
				tableData: [],
				total: 0,
				modelType: '',
				show: false,
				showModel: false,
			};
		},
		computed: {
			postData() {
				let data = {
					analysis_customer_name: this.form.analysis_customer_name,
					type: this.form.type,
					analysis_type1: this.form.analysis_type1,
					create_name: this.form.create_name,
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				if (this.form.time && this.form.time.length > 0) {
					data.start_time = this.form.time[0] / 1000;
					data.end_time = this.form.time[1] / 1000;
				}
				if (this.form.ctime && this.form.ctime.length > 0) {
					data.l_post_date_start = this.form.ctime[0] / 1000;
					data.l_post_date_end = this.form.ctime[1] / 1000;
				}
				return data;
			},
		},
		watch: {
			customer_name(newVal) {
				this.analysis_customer_id = newVal.split('_')[0] || '';
				this.analysis_customer_name = newVal.split('_')[1] || ''
				if (this.time && this.time.length)
					this.getDebiousData()
			},
			time: {
				handler(newVal) {
					if (this.analysis_customer_id && this.type)
						this.getDebiousData()
				},
				deep: true
			},
			type(newVal) {
				switch (newVal) {
					case '1':
					case '2':
						this.getEnterpriseData(newVal.value);
						break;
					case '3':
						this.getEmployeeData();
						break;
					case '4':
						this.getRData();
						break;
					case '5':
						this.getPData();
						break;
				}
			},
		},
		components: {reportModel, datePicker},
		methods: {
			getDebiousData() {
				let postData = {
					analysis_customer_id: this.analysis_customer_id,
					type: this.type,
				}
				if (this.time && this.time.length) {
					postData['l_post_date_start'] = this.time[0] / 1000;
					postData['l_post_date_end'] = this.time[1] / 1000
				}
				this.$axios.post(this.$api.g_getAnalysisDebiousNum, {...postData}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.debious_num = data.debious_num || 0
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			getEnterpriseData(type) {
				this.$axios.post(this.$api.g_companyList, {
					company_type: type,
					pagination: {
						page_start: 1,
						page_size: 9999
					}
				}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.optionList = data.list.filter(item => {
							item.value = `${item.company_id}_${item.company_name}`;
							item.label = item.company_name
							return item;
						})
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			getEmployeeData() {
				this.$axios.post(this.$api.admin_employeeList, {
					pagination: {
						page_start: 1,
						page_size: 9999
					}
				}).then(res => {
					let {code, msg, data} = res;
					if (code == 200) {
						this.optionList = data.list.filter(item => {
							item.value = `${item.employee_id}_${item.employee_name}`;
							item.label = item.employee_name
							return item;
						})
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			getRData() {
				this.$axios.post(this.$api.g_regulatedList, {
					pagination: {
						page_start: 1,
						page_size: 9999
					}
				}).then(res => {
					let {code, msg, data} = res;
					if (code == 200) {
						this.optionList = data.list.filter(item => {
							item.value = `${item.regulated_id}_${item.regulated_name}`;
							item.label = item.regulated_name
							return item;
						})
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			getPData() {
				this.$axios.post(this.$api.listContactPolice, {
					pagination: {
						page_start: 1,
						page_size: 9999
					}
				}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.optionList = data.list.filter(item => {
							item.value = `${item.id}_${item.name}`;
							item.label = item.name
							return item;
						})
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			closeModel() {
				this.type = '';
				this.customer_name = '';
				this.analysis_customer_id = '';
				this.analysis_customer_name = ''
				this.showModel = false
				this.result = ''
				this.debious_num = ''
			},
			submitModel() {
				if (!this.type) this.$message.error('请选择评估报告类型');
				if (!this.analysis_customer_id) this.$message.error('请选择评估对象');
				if (this.time && !this.time.length) this.$message.error('请选择统计时间');
				if (!this.result) this.$message.error('请输入评估结果');
				let postData = {
					type: this.type,
					analysis_customer_id: this.analysis_customer_id,
					analysis_customer_name: this.analysis_customer_name,
					result: this.result,
					debious_num: this.debious_num,
				}
				if (this.time && this.time.length) {
					postData['start_time'] = this.time[0] / 1000;
					postData['end_time'] = this.time[1] / 1000
				}
				this.$axios.post(this.$api.g_saveAnalysisInfo, {...postData}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.getData();
						this.$message.success(msg)
						this.closeModel()
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			close() {
				this.modelType = '';
				this.show = false;
			},
			dropdown(data) {
				this.modelType = data.type || '';
				this.show = true;
			},
			createReport() {
				this.showModel = true;
			},
			//导出
			exportExcel() {
				this.$import_excal(this.download_url || "");
			},
			sizeChange(val) {
				this.form.page_size = val;
				this.getData()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.getData()
			},
			filterChange(data) {
				this.form = {...this.form, ...data};
				this.getData();
			},
			getData() {
				this.loading = true;
				this.tableData = [];
				this.$axios.post(this.$api.g_getAnalysisList, {...this.postData}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.tableData = data.list.filter(item => {
							item.detail = this.isLook || true;
							item.download = this.isDownload || true;
							item.put = this.isPut || true;
							item.delete = this.isDel || true;
							return item;
						});
						this.total = data.pagination.total_count || 0;
					} else {
						this.total = 0;
						this.tableData = [];
					}
				}).catch(ret => {
					this.loading = false;
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			tableClick(data, type) {
				switch (type) {
					case 'detail':
						this.$toRoutePath({
							path: '/risk_report_list/risk_report_detail',
							edit: true,
							query: {
								detail: JSON.stringify(data)
							}
						})
						break;
					case 'put':
						this.$toRoutePath({
							path: "/notification_list/notification_detail",
							edit: true,
							query: {type: 'put', risk_assmessment_name: data.type_str}
						});
						break;
					case 'delete':
						this.$confirm("此操作将永久删除该报告, 是否继续", "提示", {
							confirmButtonText: "确定",
							cancelButtonText: "取消",
							type: "warning",
							customClass: 'message',
							closeOnClickModal: false
						}).then(() => {
						// 	this.$axios.post(this.$api.rmfeelog, {
						// 		id: data.id
						// 	}).then(res => {
						// 		let {code, msg, data} = res;
						// 		this.loading = false;
						// 		if (code == 200) {
						// 			this.$message.success(msg);
						// 			this.getData();
						// 		} else {
						// 			this.$message.error(msg);
						// 		}
						// 	}).catch(ret => {
						// 		this.$message.error(ret.msg || '服务繁忙，请稍后再试');
						// 	});
						}).catch(() => {
							this.$message("已取消删除");
						});
						break;
				}
			},
		},
		mounted() {
			this.getData();
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/government/riskAssessmentManage/report/index.less">

</style>
